<?php

	class FacebookFanPage extends Facebook_fan_page_model {

		function __construct() {
			parent::__construct();
		}
                
                function validate() {
                    parent::validate();
                    
                    if (!$this->id)
                        MessageHandler::add('Fanpage ID not found');
                    
                    if (!$this->name)
                        MessageHandler::add('Fanpage name not found');
                    
                    if (!$this->link)
                        MessageHandler::add('Fanpage link not found');
                    
                    return MessageHandler::countError() > 0 ? false : true;
                }
                
                public static function updateData($obj) {
                    
                    $fan_page = new FacebookFanPage();
                    $fan_page->get($obj->id);
                    
                    $fan_page->name = $obj->name;
                    $fan_page->link = $obj->link;
                    $fan_page->category = isset($obj->category) ? $obj->category : '';
                    $fan_page->likes = isset($obj->likes) ? $obj->likes : 0;
                    $fan_page->checkins = isset($obj->checkins) ? $obj->checkins : 0;
                    $fan_page->description = isset($obj->description) ? $obj->description : '';
                    $fan_page->misison = isset($obj->misison) ? $obj->misison : '';
                    $fan_page->products = isset($obj->products) ? $obj->products : '';
                    $fan_page->phone = isset($obj->phone) ? $obj->phone : '';
                    $fan_page->website = isset($obj->website) ? $obj->website : '';
                    $fan_page->username = isset($obj->username) ? $obj->username : '';
                    $fan_page->city = isset($obj->location->city) ? $obj->location->city : '';
                    $fan_page->country = isset($obj->location->country) ? $obj->location->country : '';
                    $fan_page->picture = isset($obj->picture) ? $obj->picture : '';
                    
                    if (!$fan_page->id) {
                        $fan_page->id = $obj->id;
                        if ($fan_page->insert())
                            return $fan_page;
                    }
                    else {
                        if ($fan_page->update())
                            return $fan_page;
                    }
                    
                    return false;
                }
	}
